package com.dxb.test.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * ClassName：com.dxb.test.map.MapRemove <br>
 * Description：TODO <br>
 *
 * @author 戴晓波 <br>
 * Date 2021/12/8/008 14:16 <br>
 * @version v1.0 <br>
 */
public class MapRemove {
    private static Map<Integer, String> map = new HashMap<Integer, String>();

    public static void main(String[] args) {
        //init
        for (int i = 0; i < 10; i++) {
            map.put(i, "value" + i);
        }
        Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Integer, String> entry = it.next();
            Integer key = entry.getKey();
            if (key % 2 == 0) {
                System.out.println("To delete key " + key);
                it.remove();
                System.out.println("The key " + +key + " was deleted");

            }
        }
    }
}
